﻿using B.S.ProductionProject.Domain;
using SqlSugar;

namespace B.S.ProductionProject.Infraturvture
{
    public class ProductionProjectContextDB
    {
        public SqlSugarClient db { get; }

        public ProductionProjectContextDB()
        {
            db = new SqlSugarClient(new ConnectionConfig()
            {
                DbType = DbType.SqlServer,
                ConnectionString = "Server=10.223.8.81;DataBase=wanghaoran1;Uid=sa;Pwd=123456;Encrypt=True;TrustServerCertificate=True;",
                IsAutoCloseConnection = true,
                InitKeyType = InitKeyType.Attribute,
            });

            db.DbMaintenance.CreateDatabase();
            db.CodeFirst.InitTables(typeof(ProductionPlanning));
            db.CodeFirst.InitTables(typeof(ProductionScheduleDetail));

            db.Aop.OnLogExecuting = (sql, pars) =>
            {
                Console.WriteLine($"执行SQL:{sql},参数:{sql}");
            };
        }
    }
}
